package com.dycx.common.enums;

import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 性别枚举值
 * @date 2023/2/23
 */
@Getter
public enum GenderEnum {
    MAN(1, "男"),
    WOMAN(2, "女");
//    UNKNOWN(0, "保密");

    private final Integer code;
    private final String name;

    GenderEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String converter(Integer code) {
        String name = "";
        for (GenderEnum item : GenderEnum.values()) {
            if (item.code.equals(code)) {
                name = item.getName();
            }
        }
        return name;
    }

    /**
     * 转为数据
     *
     * @return 枚举对象数组
     */
    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> list = new ArrayList<>();
        for (GenderEnum item : GenderEnum.values()) {
            Map<String, Object> map = new HashMap<>();
            map.put("code", item.getCode());
            map.put("name", item.getName());
            list.add(map);
        }
        return list;
    }
}
